import { Controller } from "../../mvc/core/Controller";
import { DataEvent } from "../events/DataEvent";
import { GameMapUtil } from "../scene/map/GameMapUtil";
import { IDialogMarryModule } from "../../../modules/interfaces/IDialogMarryModule";
import { OperateInfo } from "../model/OperateInfo";
import { GameManager } from "../manager/GameManager";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { IView } from "../../mvc/interfaces/IView";
import { DialogMarryModule } from "../../../modules/DialogMarryModule";
//class DialogMarryController
    
    export  class DialogMarryController extends Controller
    {
       

        /* internal  */onMarryNpcOpenHandler(arg1: DataEvent): void
        {
            if (GameMapUtil.curMapState.isCrossCountry) 
            {
                if (cache.dialog.getNPCTalk() == "" || cache.dialog.getNPCTalk() == null) 
                {
                    if (!(_view == null) && !_view.isHide) 
                    {
                        _view.hide();
                    }
                    return;
                }
            }
            (view as IDialogMarryModule).updateList(cache.dialog.npcInfo, cache.dialog.getNPCTalk(), cache.dialog.operateList);
            if (view.isHide) 
            {
                view.show();
            }
            else 
            {
                view.layer.setTop(view as Object /* flash.display.DisplayObject */);
            }
            return;
        }

        /* internal  */onMarryOptReq(arg1: DataEvent): void
        {
            var loc1=arg1.data as OperateInfo;
            GameManager.instance.popupWindow(loc1.operateId);
            view.hide();
            return;
        }

        protected /* override */ initServer(): void
        {
            super.initServer();
            Dispatcher.addEventListener(EventName.MarryNpcOpen, this.onMarryNpcOpenHandler);
            return;
        }

        protected /* override */ initView(): IView
        {
            var loc1=new DialogMarryModule();
            loc1.addEventListener(EventName.MarryNpcOptReq, this.onMarryOptReq);
            return loc1;
        }
    }
